using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using Utility;
public partial class Admin_DanhSachDonHang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }


    private void LoadData()
    {
        pager.PageSize = 5;
        Criteria c = new Criteria();
        if (txt_TenKH.Text != "")
        {
            c.add(Condition.AND + "tbKhachHang.makh=tbHoaDon.khachhang and ", tbKhachHangColumns.hotenkh, Condition.LIKE, txt_TenKH.Text);
        }
        int total = 0;
        tbHoaDonCollection hoadonCollection = tbHoaDonBUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize, tbHoaDonColumns.mahd.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = hoadonCollection;
        Repeater1.DataBind();
        pager.ItemCount = total;
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoadData();
    }
    //protected void lbt_Xoa_Click(object sender, EventArgs e)
    //{
    //    for (int i = 0; i < Repeater1.Items.Count; i++)
    //    {
    //        CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
    //        if (cb_Xoa.Checked == true)
    //        {
    //            HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
    //            int id = int.Parse(hf_id.Value);
    //            tbHoaDonBUS.UpdateTrangThai(id);
    //        }
    //    }
    //    Response.Redirect(Request.RawUrl);
    //}
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
           e.Item.ItemType == ListItemType.Item)
        {
            Literal lit_khachhang = (Literal)e.Item.FindControl("lit_tenKH");
            tbHoaDon hoadon = (tbHoaDon)e.Item.DataItem;

            //tbTinhTrangThanhToan tttt = tbTinhTrangThanhToanBUS.GetByID(hoadon.tinhtrangthanhtoan);
            //HyperLink hyp_tinhtrangthanhtoan = (HyperLink)e.Item.FindControl("hyp_tinhtrangthanhtoan");
            //hyp_tinhtrangthanhtoan.Text = tttt.tentt;
            //hyp_tinhtrangthanhtoan.NavigateUrl = "~/Admin/ChiTietHoaDon.aspx?id=" + hoadon.tinhtrangthanhtoan;
            Literal lit_ngaydathang = (Literal)e.Item.FindControl("lit_ngaydathang");
            Literal lit_ngaygiaohang = (Literal)e.Item.FindControl("lit_ngaygiaohang");
            tbPhuongThucThanhToan pttt = tbPhuongThucThanhToanBUS.GetByID(hoadon.phuongthucthanhtoan);
            HyperLink hyp_phuongthuc = (HyperLink)e.Item.FindControl("hyp_phuongthucthanhtoan");
            hyp_phuongthuc.Text = pttt.tenpt.ToString();
            hyp_phuongthuc.NavigateUrl = "~/Admin/danhsachphuongthucthanhtoan.aspx?id=" + hoadon.phuongthucthanhtoan;
            tbTinhTrangGiaoHang gh = tbTinhTrangGiaoHangBUS.GetByID(hoadon.tinhtranggiaohang);
            HyperLink hyp_giaohang = (HyperLink)e.Item.FindControl("hyp_tinhtranggiaohang");
            hyp_giaohang.Text = gh.tenttgh.ToString();
            hyp_giaohang.NavigateUrl = "~/Admin/Updatetinhtranggiaohang.aspx?id=" + hoadon.mahd ;

            tbKhachHang khachhang = tbKhachHangBUS.GetByID(hoadon.khachhang);
            HyperLink hpl_mahd = (HyperLink)e.Item.FindControl("hpl_mahd");
            hpl_mahd.Text = hoadon.mahd.ToString();
            hpl_mahd.NavigateUrl = "~/Admin/ChiTietHoaDon.aspx?id=" + hoadon.mahd;
            lit_khachhang.Text = khachhang.hotenkh;
            Literal lit_diachinhanhang = (Literal)e.Item.FindControl("lit_diachinhanhang");
            Literal lit_dienthoai = (Literal)e.Item.FindControl("lit_dienthoai");
            //hyp_tinhtrangthanhtoan.NavigateUrl = "~/Admin/UpdateTinhTrangThanhToan.aspx?id=" + hoadon.mahd.ToString();

        }
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
    //protected void btn_Update_Click(object sender, EventArgs e)
    //{
    //    for (int i = 0; i < Repeater1.Items.Count; i++)
    //    {
    //        CheckBox cb_xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_xoa");
    //        if (cb_xoa.Enabled == true && cb_xoa.Checked == true)
    //        {
    //            HiddenField hf_ID = (HiddenField)Repeater1.Items[i].FindControl("hf_ID");
    //            tbHoaDon hoadon = tbHoaDonBUS.GetByID(int.Parse(hf_ID.Value));
    //            hoadon.tinhtrangthanhtoan = true;
    //            tbHoaDonBUS.Update(hoadon);
    //        }

    //    }
    //    Response.Redirect(Request.RawUrl);
    //}
}
